/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package trumpet.gui.buddylist;

/**
 *
 * @author Artur
 */
import javax.swing.*;
import java.awt.*;
import java.util.*;
import trumpet.core.User;

public class BuddyListCellRenderer extends DefaultListCellRenderer {
  private Hashtable iconTable = new Hashtable();

  public Component getListCellRendererComponent(JList list,
                                                Object value,
                                                int index,
                                                boolean isSelected,
                                                boolean hasFocus) {
    JLabel label =
      (JLabel)super.getListCellRendererComponent(list,
                                                 value,
                                                 index,
                                                 isSelected,
                                                 hasFocus);
    if (value instanceof User) {
      User user = (User)value;
      ImageIcon icon = (ImageIcon)iconTable.get(value);
      if (icon == null) {
//        icon = new ImageIcon(user);
        iconTable.put(value, icon);
      }
      label.setIcon(icon);
    } else {
      // Clear old icon; needed in 1st release of JDK 1.2
      label.setIcon(null);
    }
    return(label);
  }
}
